package org.pi.common.snippets

object SimpleAction {
	private var f: java.awt.Frame = null;

	def apply(name: String)(fun: => Unit ): Unit = {
	    if (f==null) {
	    	f = new java.awt.Frame()
	    	f.setLayout(new java.awt.GridLayout(2,3))
	    }
	    val b = new java.awt.Button(name)
	    f.add(b)
	    b.addActionListener(new java.awt.event.ActionListener{
	      override def actionPerformed(event: java.awt.event.ActionEvent) {
	        fun
	      }
	    })
	    f.addWindowListener(new java.awt.event.WindowAdapter{
	      override def windowClosing(event: java.awt.event.WindowEvent) {
	        f.dispose()
	        //f=null
	      }
	    })
	    f.setTitle("Actions:")
	    f.pack()
	    f.setSize(f.getPreferredSize)
	    f.setVisible(true)
	}
}
